package com.example.Windturbine.Listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.Windturbine.Controller.ViewObject.Excel.QAExcel;
import com.example.Windturbine.Dao.ChickenDOMapper;
import com.example.Windturbine.DataObject.ChickenDO;
import org.springframework.beans.BeanUtils;

/**
 * @Author 丁永新
 * @Date 2022/2/7
 */
public class ExcelChickenListener extends AnalysisEventListener<QAExcel> {


    ChickenDOMapper chickenDOMapper;

    public ExcelChickenListener(ChickenDOMapper chickenDOMapper) {
        this.chickenDOMapper = chickenDOMapper;
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    @Override
    public void invoke(QAExcel qaExcel, AnalysisContext analysisContext) {
        if(qaExcel.getQuestion()==null||qaExcel.getAnswer()==null) return;
        ChickenDO qado = new ChickenDO();
        BeanUtils.copyProperties(qaExcel, qado);
        chickenDOMapper.insertSelective(qado);
    }
}
